package day15;

import java.util.*;

public class SiftGirl {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            Set<Girl> girlSet = new HashSet<>();
            int count = sc.nextInt();
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            int d = sc.nextInt();
            for (int i = 0; i < count; i++) {
                Girl girl = new Girl(sc.next(), sc.nextInt(), sc.nextInt(), sc.next());
                girlSet.add(girl);
            }
            for (Girl girl : girlSet) {
                if (girl.getHeight() >= a && girl.getHeight() <= b && girl.getAge() >= c && girl.getAge() <= d)
                    System.out.println(girl);
            }
        }
    }
}


class Girl implements Comparable<Girl> {
    private String name;
    private Integer height;
    private Integer age;
    private String number;

    public Girl(String name, Integer height, Integer age, String number) {
        this.name = name;
        this.height = height;
        this.age = age;
        this.number = number;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getHeight() {
        return height;
    }

    public void setHeight(Integer height) {
        this.height = height;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    @Override
    public String toString() {
        return name + " " + height + " " + age + " " + number;
    }


    @Override
    public int compareTo(Girl o) {
        if (o.getHeight()-this.getHeight()==0) {
            return o.getAge().compareTo(this.getAge());
        } else {
            return this.getHeight() - o.getHeight();
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Girl girl = (Girl) o;
        return Objects.equals(name, girl.name) && Objects.equals(height, girl.height) && Objects.equals(age, girl.age) && Objects.equals(number, girl.number);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, height, age, number);
    }
}

